package com.san.metadata.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.san.common.utils.PageUtils;
import com.san.common.utils.Query;
import com.san.metadata.dao.DataSourceDao;
import com.san.metadata.domain.DataSourceDO;
import com.san.metadata.service.DataSourceService;

/**
 * 数据源管理服务实现类
 * 
 * @author xiangyz
 *
 */
@Service
public class DataSourceServiceImpl implements DataSourceService {

	@Autowired
	private DataSourceDao dataSourceMapper;

	@Override
	public List<DataSourceDO> getAllSource() throws Exception {
		return dataSourceMapper.findListSource(null);
	}

	@Override
	public PageUtils findListSource(Query query) throws Exception {
		List<DataSourceDO> list = dataSourceMapper.findListSource(query);
		int total = dataSourceMapper.findListSourceCount(query);

		PageUtils pageUtils = new PageUtils(list, total);

		return pageUtils;

	}

	@Override
	public int save(Object obj) throws Exception {
		return dataSourceMapper.save(obj);
	}

	@Override
	public Object getById(Long sourceId) throws Exception {
		return dataSourceMapper.getById(sourceId);
	}

	@Override
	public int doEdit(Object obj) throws Exception {
		return dataSourceMapper.doEdit(obj);
	}

	@Override
	public int remove(Long sourceId) {
		return dataSourceMapper.remove(sourceId);
	}

	@Override
	public int batchRemove(Long[] sourceIds) {
		return dataSourceMapper.batchRemove(sourceIds);
	}

	@Override
	public List<DataSourceDO> findSource(Map<String, Object> condition) throws Exception {
		return dataSourceMapper.findListSource(new Query(condition));
	}

	@Override
	public DataSourceDO getByCode(String sourceCode) throws Exception {
		return dataSourceMapper.getByCode(sourceCode);
	}

}
